package com.hspedu.homework;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

/**
 * @author DL5O
 * @version 1.0
 */
public class Homework01 {
    public static void main(String[] args) {
        News news1 = new News("新闻一");
        news1.setContent("新冠确证病例超千万，数百万印度教信徒赴恒河\"圣浴\"引起民众担忧");
        News news2 = new News("新闻二");
        news2.setContent("男子突然想起两个月前钓的鱼还在网兜，捞起一看赶紧放生");

        ArrayList list = new ArrayList();
        list.add(news1);
        list.add(news2);
        Collections.reverse(list);//第一种倒序遍历
        Iterator iterator = list.iterator();

        while (iterator.hasNext()) {
            News news =  (News)iterator.next();
            //进行一个向下转型，对news实例相关属性进行操作
            String oldContent = news.getContent();
            String temp = "...";
            if( oldContent.length() >= 15){
                //方式一:
                String newContent = oldContent.substring(0,15) + temp;
                news.setContent(newContent);
            }
            System.out.println(news);
        }


       /* //第二种倒序遍历
        for (int i = list.size() - 1; i >=0 ; i--) {
            System.out.println(list.get(i));
        }*/


    }
}

class News{
    private String title;
    private String content;

    public News(String title) {
        this.title = title;
    }

    @Override
    public String toString() {
        return  title + ':' + content ;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }
}
